class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int dest = 0, cur = 0;
        int sum = 0;
        int len = INT_MAX;
        while (cur < nums.size()) {
            sum=sum+nums[cur];
            while(sum>=target)
            {
                len=min(len,cur-dest+1);
                sum=sum-nums[dest];
                dest++;
            }
            cur++;
        }
        if(len==INT_MAX)
        {
            return 0;
        }
        return len;
    }
};
